local mosong = fk.CreateSkill {
  name = "th_mosong",
  derived_piles = "th_byakuren_song",
}

mosong:addEffect(fk.EventPhaseProceeding, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(mosong.name) and player.phase == Player.Draw and not data.phase_end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(5)
    player:addToPile("th_byakuren_song", cards, true, mosong.name)
    data.phase_end = true
    if #player:getPile("th_byakuren_song") == 0 then return end
    local gain = room:askToPoxi(player, {
      poxi_type = "th_mosong",
      data = { {"th_byakuren_song", player:getPile("th_byakuren_song")} },
      cancelable = false
    })
    room:obtainCard(player, gain, true, fk.ReasonJudge, player.id, mosong.name)
  end
})
mosong:addEffect(fk.DamageCaused, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and #player:getPile("th_byakuren_song") >= 2
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 2,
      max_num = 2,
      include_equip = false,
      skill_name =  mosong.name,
      cancelable = true,
      pattern = ".|.|.|th_byakuren_song|.|.|.",
      prompt = "#th_mosong-invoke",
      expand_pile = "th_byakuren_song"
    })
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, mosong.name, nil, true, player)
      data:changeDamage(1)
    end
  end
})

Fk:addPoxiMethod{
  name = "th_mosong",
  card_filter = function(to_select, selected, data, extra_data)
    if #selected > 0 then
      return Fk:getCardById(selected[1]).suit == Fk:getCardById(to_select).suit
    else
      return true
    end
  end,
  feasible = function(selected, data, extra_data)
    return #selected > 0
  end,
  prompt = function(data, extra_data)
    return "#th_mosong-get"
  end,
  default_choice = function(data, extra_data)
    return {data[1][2][1]}
  end
}

Fk:loadTranslationTable{
  ["th_mosong"] = "魔诵",
  [":th_mosong"] = "摸牌阶段，你可以改为将牌堆顶的五张牌置于武将牌上，称为“颂”，然后获得任意张相同花色的“颂”。有“颂”的角色造成伤害时，其可以弃置两张“颂”并令此伤害+1。",

  ["#th_mosong-get"] = "魔诵：请选择任意张相同花色的“颂”获得之",
  ["#th_mosong-invoke"] = "魔诵：你可以弃置两张“颂”并令你造成伤害+1",

  ["th_byakuren_song"] = "颂",
}

return mosong